console.log(process.env.NODE_ENV);
const port = process.env.port || 8000;
const IS_PRODUCTION = process.env.NODE_ENV === "production";
const path = require('path');
const UglifyPlugin = require('uglifyjs-webpack-plugin')

// const webpack = require('webpack')
function resolve(dir) {
    return path.join(__dirname, dir);
}

module.exports = {

    lintOnSave: false,
    // publicPath:'./',
    outputDir: 'home',
    publicPath: process.env.NODE_ENV === 'production' ? './home/' : '',
    // lintOnSave:process.env.NODE_ENV === "development",
    devServer: {
        port,
        open: true,
        overlay: {
            warnings: false,
            errors: true
        },
        proxy: {
            "/api": {
                target: 'http://xiruolvyou.com/',
                changeOrigin: true,
                pathRewrite: {
                    "^/api": ''
                }
            }
        }
    },


    // configureWebpack: {
    //     name: "Ticket_booking",
    //     resolve: {
    //         alias: {
    //             '@': resolve('src'),
    //             'views': resolve('src/views'),
    //             'components': resolve('src/components'),
    //             'utils': resolve('src/utils'),
    //             'style': resolve('src/style'),
    //             'assets': resolve('src/assets')
    //         }
    //     },
    // },
    chainWebpack: (config) => {
        // 修复HMR
        config.resolve.symlinks(true);
        // 别名配置
        config.resolve.alias
            .set('@', resolve('src'))
            .set('views', resolve('src/views'))
            .set('components', resolve('src/components'))
            .set('utils', resolve('src/style'))
            .set('style', resolve('src/style'))
            .set('api', resolve('src/api'))
            .set('assets', resolve('src/assets'));
    },
    configureWebpack: config =>{
        if(process.env.NODE_ENV === 'production'){
            //为生产环境修改配置...
            config.mode = 'production';
            let optimization = {
                minimizer: [new UglifyPlugin({
                    uglifyOptions: {
                        warnings: false,
                        compress: {
                            drop_console: true, // console
                            drop_debugger: false,
                            pure_funcs: ['console.log'] // 移除console
                        }
                    }
                })]
            }
            Object.assign(config, {
                optimization
            })
        }else {
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
        }
    },
    pluginOptions: {
        // ...
        pwa: {
            iconPaths: {
                favicon32: './favicon.ico',
                favicon16: './favicon.ico',
                appleTouchIcon: './favicon.ico',
                maskIcon: './favicon.ico',
                msTileImage: './favicon.ico'
            }
        }
    }

};
